package com.lanhao.aot.exchager;

import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExchangerUtil {
	private static final Logger LOG = LoggerFactory.getLogger(ExchangerUtil.class);
	public static Exchanger<String> exchanger = new Exchanger<>();
	public static ExecutorService tpool = Executors.newFixedThreadPool(1);

	public static void doAsyncTask() {
		try {
			String threadName = Thread.currentThread().getName();
			String data = "这是来自线程" + threadName + "的交换数据" + System.currentTimeMillis();
			LOG.info("异步启动线程，线程名ThreadName={}, 交换数据为data={}", threadName, data);
			ExchangerUtil.exchanger.exchange(data);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
